package com.analysis.apresunday.job;
 
import com.analysis.apresunday.service.EmpDataService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 定时任务
 **/
@Component
@Slf4j
public class Task {
    @Resource
    EmpDataService empDataService;

    private List<String> keywords1 = Arrays.asList(
            "数据分析", "数据标注", "大数据工程师", "大数据架构师", "数据开发", "数据运维",
            "数据采集", "数据治理", "数据挖掘", "大数据讲师", "大数据实习", "AI工程师", "数据科学",
            "机器学习", "自然语言处理", "NLP", "爬虫", "BI", "数据治理"
    );


    private List<String> keywords2 = Arrays.asList(
            "hadoop", "python", "jupyter", "pycharm", "流处理", "Kafka", "Flink", "MapReduce", "ETL开发",
            "NoSQL", "HBase", "Cassandra", "数据安全", "ElasticSearch", "数据中台", "Spark", "scrapy",
            "数据可视化", "数据仓库", "数据湖", "TensorFlow", "Keras", "PyTorch", "实时计算",
            "Presto", "Cloudera", "Talend", "Informatica", "数据流分析", "clickhouse"
    );


    @Scheduled(cron = "0 11 12,15,20 * * ?")
    public void execute() {
        for (String keyword : keywords1) {
            boolean success = false;
            int attempts = 0;
            int maxAttempts = 10;  // 最大尝试次数

            // 当返回 false 时，继续执行该脚本，最多执行 10 次
            while (!success && attempts < maxAttempts) {
                success = empDataService.executeAutoCrawlScript(keyword);
                attempts++;
            }

            if (!success) {
                log.error("执行关键字 '{}' 脚本失败，已尝试 {} 次，放弃重试。", keyword, attempts);
                // 这里可以添加进一步的处理逻辑，例如发送通知或记录详细日志
            }
        }
    }

    @Scheduled(cron = "0 20 10,13,18 * * ?")
    public void execute2() {
        for (String keyword : keywords2) {
            boolean success = false;
            int attempts = 0;
            int maxAttempts = 10;  // 最大尝试次数

            // 当返回 false 时，继续执行该脚本，最多执行 10 次
            while (!success && attempts < maxAttempts) {
                success = empDataService.executeAutoCrawlScript(keyword);
                attempts++;
            }

            if (!success) {
                log.error("执行关键字 '{}' 脚本失败，已尝试 {} 次，放弃重试。", keyword, attempts);
                // 这里可以添加进一步的处理逻辑，例如发送通知或记录详细日志
            }
        }
    }


}